********Table 3 - Indonesia********

eststo clear

*Load data
cd "$reploc/data/created_data"
use indo_full, clear

sort pidlink ifls
drop if ifls==.
*keep if panel==1

*Do this analysis for full sample
sort pidlink ifls
foreach var of varlist rbuc_garefined rbuc grbrprovAvg_lam0co3 grbrprovSD_lam0co3 inflation{
gen `var'dif=`var'-`var'[_n-1] if ifls==5 & pidlink==pidlink[_n-1]
} 

gen eithrisk=0
replace eithrisk=1 if rbucdif!=. 

egen fullsample=total(eithrisk), by(pidlink)
keep if fullsample==1

egen rbuctot=total(rbuc), by(pidlink)
egen rav_scoremean=mean(rav_score), by(pidlink)

*Attentiveness
gen badatt=.
replace badatt=1 if b3acp3>=3 & b3acp3!=.
replace badatt=0 if b3acp3<=2 & b3acp3!=.
egen badattmean=mean(badatt), by(pidlink)

*Reliogisity
gen vreligious=.
replace vreligious=1 if religiosity==4 & religiosity!=.
replace vreligious=0 if religiosity<4 & religiosity!=.
egen vreligiousmean=mean(vreligious), by(pidlink)

egen gatot=total(gambleaverse), by(pidlink)

*Normalize
gen mth_inc_ia_use=mth_inc_ia/1000000

label define ga 0 "Never GA" 1 "Once GA" 2 "Always GA"

label values gatot ga 

qui tabstat age woman muslim vreligious rav_score badatt mth_inc_ia_use, by(gatot) stat(mean) save
qui tabstatmat B
matrix B = B'
matrix list B, f(%9.5g)

cd "$reploc/results"
esttab matrix(B) using Table3_Indonesia.tex, replace
